/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */
package br.ufmg.dees.insane.ui.rich.learn.learn_view.element_view;

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JToolBar;
import javax.swing.text.Position;

import br.ufmg.dees.insane.model.disc.fem.FemModel;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.ElementEqController;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.GridElementEqController;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdButton;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdMenu;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.DrawingArea;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.IView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnInterface;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnViewState;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.Command;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.SelectCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.element_view.command.GetCompleteForcesCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.element_view.command.GetCompleteStiffnessCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.element_view.command.GetEquilibriumCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.element_view.command.GetReduceForcesCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.element_view.command.GetReduceStiffnessCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.element_view.command.Help4Command;

/**
*
* @author Moreira, Renata & Pitangueira, Roque
* @since August 2005
*/
public class ElementView extends LearnView {  
	
	//  No da arvore: Element Equilibrium
	private Command getEquilibriumCmd = new GetEquilibriumCommand(parent);
	private Command getCompleteStiffnessCmd = new GetCompleteStiffnessCommand(parent);
	private Command getReduceStiffnessCmd = new GetReduceStiffnessCommand(parent);
	private Command getCompleteForcesCmd = new GetCompleteForcesCommand(parent);
	private Command getReduceForcesCmd = new GetReduceForcesCommand(parent);
	//private Command getCompleteNodalForcesCmd = new GetCompleteNodalForcesCommand(parent);
	//private Command getReduceNodalForcesCmd = new GetReduceNodalForcesCommand(parent);
	private Command help4Cmd = new Help4Command(parent);
	
	//	No Element Equilibrium
    private CmdMenu itemGetEquilibrium = new CmdMenu("Equilibrium", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Equil.gif")));
    private CmdMenu itemGetCompleteStiffness = new CmdMenu("Complete Stiffness", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Stifiness.gif")));
    private CmdMenu itemGetReduceStiffness = new CmdMenu("Reduce Stiffness", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/StifinessRed.gif")));
    private CmdMenu itemGetCompleteForces = new CmdMenu("Complete Forces", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Forc.gif")));
    private CmdMenu itemGetReduceForces = new CmdMenu("Reduce Forces", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ForcRed.gif")));
    //private CmdMenu itemGetCompleteNodalForces = new CmdMenu("Complete Nodal Forces", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));
    //private CmdMenu itemGetReduceNodalForces = new CmdMenu("Reduce Nodal Forces", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));
    private CmdMenu itemHelp4 = new CmdMenu("Help", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));

    
    //No Element Equilibrium
    private CmdButton getEquilibrium = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Equil.gif")));
    private CmdButton getCompleteStiffness = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Stifiness.gif")));
    private CmdButton getReduceStiffness = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/StifinessRed.gif")));
    private CmdButton getCompleteForces = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Forc.gif")));
    private CmdButton getReduceForces = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ForcRed.gif")));
    //private CmdButton getCompleteNodalForces = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));
    //private CmdButton getReduceNodalForces = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/CheckData16.gif")));
    private CmdButton help4 = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));
   
    private JMenu menuElementEquilibrium = new JMenu("Element Equilibrium");
    protected JToolBar elementEquilibriumToolBar = new JToolBar();
    
	public ElementView(LearnInterface parent, FemModel m){
	    super(parent,m);
		super.setViewState(new LearnViewState());
		super.setDrawingArea(new DrawingArea((IView)this));
		super.setController(new ElementEqController(this));
		
		String gAnlType = m.getGlobalAnalysisModel().getType();
		
		if (!(gAnlType.equals("Grid"))) {
			super.setController(new ElementEqController(this));
		} else {
			super.setController(new GridElementEqController(this));
		}
		
		
		//Setting menu Element Equilibrium
		menuElementEquilibrium.add(itemGetEquilibrium);
		itemGetEquilibrium.setCommand(getEquilibriumCmd);
		itemGetEquilibrium.setEnabled(false);
		itemGetEquilibrium.setMnemonic(KeyEvent.VK_E);
		itemGetEquilibrium.addActionListener(parent);
        
		menuElementEquilibrium.add(itemGetCompleteStiffness);
		itemGetCompleteStiffness.setCommand(getCompleteStiffnessCmd);
		itemGetCompleteStiffness.setEnabled(false);
		itemGetCompleteStiffness.setMnemonic(KeyEvent.VK_S);
		itemGetCompleteStiffness.addActionListener(parent);
		
		menuElementEquilibrium.add(itemGetReduceStiffness);
		itemGetReduceStiffness.setCommand(getReduceStiffnessCmd);
		itemGetReduceStiffness.setEnabled(false);
		itemGetReduceStiffness.setMnemonic(KeyEvent.VK_R);
		itemGetReduceStiffness.addActionListener(parent);
		
		menuElementEquilibrium.add(itemGetCompleteForces);
		itemGetCompleteForces.setCommand(getCompleteForcesCmd);
		itemGetCompleteForces.setEnabled(false);
		itemGetCompleteForces.setMnemonic(KeyEvent.VK_F);
		itemGetCompleteForces.addActionListener(parent);
		
		menuElementEquilibrium.add(itemGetReduceForces);
		itemGetReduceForces.setCommand(getReduceForcesCmd);
		itemGetReduceForces.setEnabled(false);
		itemGetReduceForces.setMnemonic(KeyEvent.VK_S);
		itemGetReduceForces.addActionListener(parent);
		
		//menuElementEquilibrium.add(itemGetCompleteNodalForces);
		//itemGetCompleteNodalForces.setCommand(getCompleteNodalForcesCmd);
		//itemGetCompleteNodalForces.setEnabled(false);
		//itemGetCompleteNodalForces.setMnemonic(KeyEvent.VK_F);
		//itemGetCompleteNodalForces.addActionListener(parent);
		
		//menuElementEquilibrium.add(itemGetReduceNodalForces);
		//itemGetReduceNodalForces.setCommand(getReduceNodalForcesCmd);
		//itemGetReduceNodalForces.setEnabled(false);
		//itemGetReduceNodalForces.setMnemonic(KeyEvent.VK_S);
		//itemGetReduceNodalForces.addActionListener(parent);
		     
		menuElementEquilibrium.add(itemHelp4);
        itemHelp4.setCommand(help4Cmd);
        itemHelp4.setEnabled(false);
        itemHelp4.setMnemonic(KeyEvent.VK_H);
        itemHelp4.addActionListener(parent);
        
        elementEquilibriumToolBar.add(getEquilibrium);
        getEquilibrium.setToolTipText("Equilibrium");
        getEquilibrium.addActionListener(parent);
        getEquilibrium.setCommand(getEquilibriumCmd);
        
        elementEquilibriumToolBar.add(getCompleteStiffness);
        getCompleteStiffness.setToolTipText("Complete Stiffness");
        getCompleteStiffness.addActionListener(parent);
        getCompleteStiffness.setCommand(getCompleteStiffnessCmd);
        
        elementEquilibriumToolBar.add(getReduceStiffness);
        getReduceStiffness.setToolTipText("Reduce Stiffness");
        getReduceStiffness.addActionListener(parent);
        getReduceStiffness.setCommand(getReduceStiffnessCmd);
        
        elementEquilibriumToolBar.add(getCompleteForces);
        getCompleteForces.setToolTipText("Complete Forces");
        getCompleteForces.addActionListener(parent);
        getCompleteForces.setCommand(getCompleteForcesCmd);
        
        elementEquilibriumToolBar.add(getReduceForces);
        getReduceForces.setToolTipText("Reduce Forces");
        getReduceForces.addActionListener(parent);
        getReduceForces.setCommand(getReduceForcesCmd);
        
        //elementEquilibriumToolBar.add(getCompleteNodalForces);
        //getCompleteNodalForces.setToolTipText("Complete Nodal Forces");
        //getCompleteNodalForces.addActionListener(parent);
        //getCompleteNodalForces.setCommand(getCompleteNodalForcesCmd);
        
        //elementEquilibriumToolBar.add(getReduceNodalForces);
        //getReduceNodalForces.setToolTipText("Reduce Forces");
        //getReduceNodalForces.addActionListener(parent);
       // getReduceNodalForces.setCommand(getReduceNodalForcesCmd);
               
        elementEquilibriumToolBar.add(help4);
		help4.setToolTipText("Help");
		help4.addActionListener(parent);
		help4.setCommand(help4Cmd);
        
	}
	
	public void init(){
	    super.init();
			parent.getMenuPanel().removeAll();
			parent.getMenuPanel().add(menuFile);
			itemSave.setEnabled(true);
			itemSaveAs.setEnabled(true);
			itemClose.setEnabled(true);
			itemPrint.setEnabled(true);
			menuExport.setEnabled(true);
			menuImport.setEnabled(true);
			parent.getMenuPanel().add(menuEdit);
			parent.getMenuPanel().add(menuView);
			parent.getMenuPanel().add(menuElementEquilibrium);
			menuElementEquilibrium.setEnabled(true);
			itemGetEquilibrium.setEnabled(true);
			itemGetCompleteStiffness.setEnabled(true);
			itemGetReduceStiffness.setEnabled(true);
			itemGetCompleteForces.setEnabled(true);
			itemGetReduceForces.setEnabled(true);
			//itemGetCompleteNodalForces.setEnabled(true);
			//itemGetReduceNodalForces.setEnabled(true);
			itemHelp4.setEnabled(true);
			parent.getMenuPanel().add(menuSettings);
			parent.getMenuPanel().add(menuHelp);
	        
			parent.getToolPanel().removeAll();
			parent.getToolPanel().add(fileToolBar);
			save.setEnabled(true);
			saveAs.setEnabled(true);
			print.setEnabled(true);
			delete.setEnabled(false);
			parent.getToolPanel().add(editToolBar);
			parent.getToolPanel().add(zoomToolBar);
			parent.getToolPanel().add(elementEquilibriumToolBar);
			getEquilibrium.setEnabled(true);
			getCompleteStiffness.setEnabled(true);
			getReduceStiffness.setEnabled(true);
			getCompleteForces.setEnabled(true);
			getReduceForces.setEnabled(true);
			//getCompleteNodalForces.setEnabled(true);
			//getReduceNodalForces.setEnabled(true);
			help4.setEnabled(true);
							
	        parent.getConsolePanel().setVisible(true);
			
			grid.setEnabled(true);
			snap.setEnabled(true);
			
			this.getDrawingArea().setRepainting(false);
			this.getDrawingArea().repaint();
	        
			parent.getConsoleHandler().setToCommandMode();
			parent.getConsoleHandler().setKeybCommand(null);
			
			this.setStateButtons();
			
			parent.getTree().setEnabled(true);
			parent.getTree().setSelectionPath(parent.getTree().getNextMatch("Element Equilibrium", 0, Position.Bias.Forward));
			
			this.getController().compose();

			parent.getDrawPanel().removeAll();
			parent.getDrawPanel().add(this.getDrawingArea(), BorderLayout.CENTER);
			this.getDrawingArea().removeAllCommands();
			this.getDrawingArea().setClickedCommand(new SelectCommand(parent));
			this.getDrawingArea().setCursor();
			parent.getDrawPanel().repaint();
			parent.getDrawPanel().updateUI();
			
			parent.getJMenuBar().updateUI();
			parent.repaint();
	    }   

	public  JFrame getInterface(){
    	return parent;
    }
    
	public void setInterface(JFrame par){
    	this.parent = (LearnInterface)par;
    }

    public void setCoord(String x, String y){
    	this.parent.setCoord(x, y);
    }
    
    public void setMessage(String m){
    	this.parent.setMessage(m);
    }

}
